package test.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.framework.ProxyFactory;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LogInterceptor implements MethodInterceptor {
	
	@Override
	public Object invoke(MethodInvocation invocation) throws Throwable {
		log.info("before...");
		Object obj = invocation.proceed();
		log.info("after...");
		return obj;
	}

	public static void main(String[] args) {
		ProxyFactory proxyFactory = new ProxyFactory();
		proxyFactory.addAdvice(new LogInterceptor());
		proxyFactory.addAdvice(new TestInterceptor());
		
		proxyFactory.setTarget(new UserService());
		
		UserService proxy = (UserService) proxyFactory.getProxy();
		
		proxy.hello("zhangsan");
	}

}
